Function Reference

_IEDocInsertText

Inserts Text in or around an element.

#include <IE.au3>
_IEDocInsertText ( ByRef $o_object, $s_string [, $s_where = "beforeend"] )

 

Parameters

$o_object Object variable pointing to a document element.
$s_string The string containing the text to insert.
$s_where Optional: specifies the string insertion point
beforebegin = Inserts string immediately before the object.
afterbegin = Inserts string after the start of the object but before all other content in the object.
beforeend = (Default) Inserts string immediately before the end of the object but after all other content in the object.
afterend = Inserts string immediately after the end of the object.

 

Return Value

Success: Returns 1
Failure: Returns 0 and sets @ERROR
@Error: 0 ($_IEStatus_Success) = No Error
3 ($_IEStatus_InvalidDataType) = Invalid Data Type
4 ($_IEStatus_InvalidObjectType) = Invalid Object Type
5 ($_IEStatus_InvalidValue) = Invalid Value
@Extended: Contains invalid parameter number

 

Remarks

In the text to be inserted includes HTML tags, they are first converted so that they display as text. The innerHTML, outerHTML, innerText and outerText features of _IEPropertySet can be used to dynamically manipulate inserted content.

 

Related

_IEDocInsertHTML, _IEPropertyGet, _IEPropertySet, _IEBodyReadHTML, _IEBodyWriteHTML, _IEDocReadHTML, _IEHeadInsertEventScript

 

Example


; *******************************************************
; Example 1 - Open a browser with the basic example page, insert text
;       in and around the first Paragraph tag and display Body HTML
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("basic")
$oP = _IETagNameGetCollection($oIE, "p", 0)

_IEDocInsertText($oP, "(Text beforebegin)", "beforebegin")
_IEDocInsertText($oP, "(Text afterbegin)", "afterbegin")
_IEDocInsertText($oP, "(Text beforeend)", "beforeend")
_IEDocInsertText($oP, "(Text afterend)", "afterend")

ConsoleWrite(_IEBodyReadHTML($oIE) & @CR)

; *******************************************************
; Example 2 - Insert HTML at the top and bottom of a document
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("basic")
$oBody = _IETagNameGetCollection($oIE, "body", 0)
_IEDocInsertText($oBody, "This Text is inserted After Begin", "afterbegin")
_IEDocInsertText($oBody, "Notice that <b>Tags</b> are <encoded> before display", "beforeend")


; *******************************************************
; Example 3 - Advanced example
;       Insert a clock and a referrer string at the top of every page, even when you
;       browse to a new location.  Uses _IEDocInsertText, _IEDocInsertHTML and  
;       _IEPropertySet features "innerhtml" and "referrer"
; *******************************************************
;
#include <IE.au3>
$oIE = _IECreate("http://www.autoitscript.com")

AdlibEnable("UpdateClock", 1000) ; Update clock once per second

; idle as long as the browser window exists
While WinExists(_IEPropertyGet($oIE, "hwnd"))
    Sleep(10000)
WEnd

Exit

Func UpdateClock()
    Local $curTime = "<b>Current Time is: </b>" & @HOUR & ":" & @MIN & ":" & @SEC
    ; _IEGetObjByName is expected to return a NoMatch error after navigation
    ;   (before DIV is inserted), so temporarily turn off notification
    _IEErrorNotify(False)
    Local $oAutoItClock = _IEGetObjByName($oIE, "AutoItClock")
    If Not IsObj($oAutoItClock) Then ; Insert DIV element if it wasn't found
        ;
        ; Get reference to BODY, insert DIV, get reference to DIV, update time
        $oBody = _IETagNameGetCollection($oIE, "body", 0)
        _IEDocInsertHTML($oBody, "<div id='AutoItClock'></div>", "afterbegin")
        $oAutoItClock = _IEGetObjByName($oIE, "AutoItClock")
        _IEPropertySet($oAutoItClock, "innerhtml", $curTime)
        ;
        ; Check referrer string, if not blank insert after clock
        _IELoadWait($oIE)
        $sReferrer = _IEPropertyGet($oIE, "referrer")
        If $sReferrer Then _IEDocInsertText($oAutoItClock, _
            "  Referred by: " & $sReferrer, "afterend")
    Else
        _IEPropertySet($oAutoItClock, "innerhtml", $curTime) ; update time
    EndIf
    _IEErrorNotify(True)
EndFunc